package com.hanggold.springboot.lesson4.conditionboostrap;


import com.hanggold.springboot.lesson4.annotation.ConditionalOnSystemPropertyCondition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConditonBoostrapDemo {

    @ConditionalOnSystemPropertyCondition(name = "language", value = "chinese")
    @Bean("message")
    public String chineseMessage() {
        return "你好,世界";
    }


    @ConditionalOnSystemPropertyCondition(name = "language", value = "english")
    @Bean("message")
    public String enlishMessage() {
        return "hello world";
    }


    public static void main(String[] args) {

        System.setProperty("language","english");

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();

        annotationConfigApplicationContext.register(ConditonBoostrapDemo.class);

        annotationConfigApplicationContext.refresh();

        String message = (String) annotationConfigApplicationContext.getBean("message");

        System.out.println("你輸出的messge : " + message);


    }


}
